<template>
    <view class="wrap">
        <view class="">
            <view class="top-banner-wrap" @click="choosePhoto">
                <image class="top-banner" src="@/pages/minePages/static/addFootprint/default.jpg" mode="aspectFill"></image>
                <view class="mask"></view>
                <view class="upload-box">
                    <image src="@/pages/minePages/static/addFootprint/upload-icon.png" mode=""></image>
                    <view class="u-m-t-32">上传你的照片</view>
                </view>
            </view>
            <view class="details">
                <view class="title">
                    这一天，你来到了
                    <span>
                        {{ locationName }}
                        <input class="input" maxlength="10" v-model="locationName" />
                    </span>
                    ，照片记录了你的足迹
                </view>
                <view class="date-wrap" @click="throttleSelect">
                    <image src="@/pages/minePages/static/footprintDetail/date-icon.png" mode=""></image>
                    <view :class="{ selected: date }">{{ date || '点击选择时间' }}</view>
                    <u-calendar v-model="showCalenda" mode="date" @change="dateChange"></u-calendar>
                </view>
                <view class="location-wrap" @click="throttleLocation">
                    <image src="@/pages/minePages/static/footprintDetail/location-icon.png" mode=""></image>
                    <view :class="{ selected: locationName }">{{ locationName || '点击定位' }}</view>
                </view>
                <view class="map"><map style="width: 100%; height:100%;" :latitude="latitude" :longitude="longitude"></map></view>
            </view>
        </view>
        <view class="submit" @click="submit">提交</view>
    </view>
</template>
<script>
import { formate } from '@/common/utils.js';
import { uploadFile } from '@/common/utils.js';
export default {
    name: '',
    data() {
        return {
            locationName: '',
            showCalenda: false,
            date: '',
            locationName: '',
            latitude: 39.909,
            longitude: 116.39742,
            // covers: [
            //     {
            //         latitude: 39.909,
            //         longitude: 116.39742,
            //         iconPath: '../../../static/location.png'
            //     },
            //     {
            //         latitude: 39.9,
            //         longitude: 116.39,
            //         iconPath: '../../../static/location.png'
            //     }
            // ]
        };
    },
    props: {
        name: {
            type: String,
            default: ''
        }
    },
    computed: {},
    onLoad() {},
    onShow() {},
    methods: {
        async choosePhoto() {
            let photo = await this.$uniPromise.chooseImage({ count: 1 });
            if (photo && photo.tempFilePaths.length > 0) {
                this.upload(photo.tempFilePaths[0]);
            }
        },
        // 开始上传照片
        upload(path) {
            setTimeout(() => {
                uni.showLoading({
                    title: '上传中',
                    mask: true
                });
            }, 500);
            uploadFile(`${this.$config.baseUrl}/api/upload/obs`, path, this.$config.tokenKey, {}, true)
                .then(res => {
                    if (res.RequestStatus === 100 && res.Data && res.Data.image_url) {
                        console.log(res);
                        uni.hideLoading();
                    } else {
                        uni.hideLoading();
                    }
                })
                .catch(err => {
                    uni.hideLoading();
                });
        },
        throttleSelect() {
            this.$u.throttle(this.selectDate, 3000);
        },
        selectDate() {
            this.showCalenda = true;
        },
        dateChange(e) {
            this.date = e.year + '.' + formate(e.month) + '.' + formate(e.day);
        },
        throttleLocation() {
            this.$u.throttle(this.chooseLocation, 3000);
        },
        chooseLocation() {}
    },
    watch: {},
    components: {}
};
</script>
<style lang="scss" scoped>
.wrap {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100vh;
    .top-banner-wrap {
        position: relative;
        left: 0;
        top: 0;
        width: 750rpx;
        height: 500rpx;
        .top-banner {
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            -webkit-filter: blur(20rpx);
            filter: blur(20rpx);
        }
        .mask {
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            z-index: 1;
            background: rgba(0, 0, 0, 0.5);
        }
        .upload-box {
            position: relative;
            left: 50%;
            top: 60rpx;
            transform: translate(-50%, 0);
            z-index: 3;
            width: 630rpx;
            height: 330rpx;
            border-radius: 10rpx;
            border: 2rpx dashed #ffffff;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            font-size: 30rpx;
            color: #ffffff;
            image {
                width: 126rpx;
                height: 92rpx;
            }
        }
    }

    .details {
        position: relative;
        z-index: 1;
        margin-top: -50rpx;
        background: #fff;
        border-radius: 10rpx 10rpx 0 0;
        padding: 45rpx 30rpx 30rpx;
        .title {
            font-size: 32rpx;
            font-weight: bold;
            padding-bottom: 35rpx;
            span {
                position: relative;
                border-bottom: 2rpx solid #000;
                padding: 0 30rpx;
            }
            input {
                position: absolute;
                left: 0;
                top: 0;
                width: 100%;
                height: 100%;
                opacity: 0;
                text-align: center;
                background: #000;
            }
        }
        .date-wrap,
        .location-wrap {
            display: flex;
            font-size: 26rpx;
            line-height: 26rpx;
            align-items: center;
            color: #abb3b8;
        }
        .selected {
            color: #262832;
        }
        .date-wrap {
            padding-bottom: 30rpx;
            image {
                width: 28rpx;
                height: 28rpx;
                margin-right: 20rpx;
            }
        }
        .location-wrap {
            padding-bottom: 50rpx;
            image {
                width: 24rpx;
                height: 30rpx;
                margin-right: 20rpx;
            }
        }
        .map {
            width: 690rpx;
            height: 296rpx;
            border-radius: 6rpx;
        }
    }
    .submit {
        width: 750rpx;
        height: 98rpx;
        background-color: #ffffff;
        box-shadow: 0rpx -6rpx 40rpx 0rpx rgba(0, 0, 0, 0.05);
        flex-shrink: 0;
        display: flex;
        justify-content: space-around;
        align-items: center;
        font-size: 30rpx;
        line-height: 30rpx;
        color: #20bf64;
    }
}
</style>
